#include <QtGui/QApplication>
#include "gameview.h"
#include "menuscene.h"

// globals
QString resourcePath;

int main(int argc, char *argv[])
{
    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    #if QT_VERSION >= 0x040500
        QApplication::setGraphicsSystem("raster");
    #endif

    QApplication a(argc, argv);

    resourcePath = QApplication::applicationDirPath();
    resourcePath.chop(3);
    resourcePath += "data/";

    // on X11, we'll check if data directory exists locally first
    #ifdef Q_WS_X11
    if (!QDir(resourcePath).exists())
    {
        resourcePath = "/usr/share/games/qt-td/";
    }
    #endif

    QTranslator appTranslator, qtTranslator;
    QString lng =  QLocale::system().name();
    lng.chop(3);
    qtTranslator.load("qt_" + lng, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    appTranslator.load("game_" + lng, ":/lang/data/lang/");
    a.installTranslator(&qtTranslator);
    a.installTranslator(&appTranslator);

    /*if (!QDir(resourcePath).exists())
    {
        QMessageBox::critical(0, QObject::tr("Files are missing"),
                                 QObject::tr("Cannot find data folder<br><b>%1</b><br> Exiting...").arg(resourcePath),
                                 QMessageBox::Close);
        QApplication::quit();
        return -1;
    }*/

    GameView view;
    MenuScene * menuScene = new MenuScene(&view);
    QObject::connect(menuScene, SIGNAL(newGame()), &view, SLOT(newGame()));
    view.setScene(menuScene);
    //view.viewport()->setMouseTracking(true);
    view.show();

    int result = a.exec();

    return result;
}
